package com.powervision.sharesdkdemo.app;

import android.app.Application;
import android.util.Log;

import com.mob.MobSDK;
import com.mob.tools.utils.Hashon;
import com.powervision.sharesdkdemo.base.BaseActivity;
import com.powervision.sharesdkdemo.bean.ResourcesManager;
import com.powervision.sharesdkdemo.utils.ShareUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.framework.loopshare.LoopShareResultListener;

/**
 * @auth: njb
 * @date: 2021/10/18 15:46
 * @desc: 描述
 */
public class MyApp extends Application {
    private BaseActivity currentActivity;
    public List<Platform> platformList = new ArrayList<>();
    public  static MyApp app = null;

    @Override
    public void onCreate() {
        super.onCreate();
        initShareSdk();
        initWeChat();
    }

    private void initWeChat() {
        ShareUtils.regToWx(this);
    }

    private void initShareSdk() {
        //loopshare init and set Listener
        ShareSDK.prepareLoopShare(new LoopShareResultListener() {
            @Override
            public void onResult(Object var1) {
                String test = new Hashon().fromHashMap((HashMap<String, Object>) var1);
                Log.e("WWW", "LoopShareResultListener onResult " + test);
            }

            @Override
            public void onError(Throwable t) {
                Log.e("WWW", "LoopShareResultListener onError " + t);
            }
        });
        Log.e("WWW", " ShareSDK.prepareLoopShare() successed ");

        this.app = this;
        ResourcesManager.getInstace(MobSDK.getContext());
        ShareUtils.get().initMobSDK(this);
    }

    //todo test

    public static MyApp getInstance(){
        return app;
    }

    public List<Platform> getPlatformList() {
        return platformList;
    }

    public void setPlatformList(Platform platform) {
        if(platformList.size() > 0){
            platformList.clear();
        }
        if(platform != null){
            platformList.add(platform);
        }
    }

    public void setCurrentActivity(BaseActivity activity){
        this.currentActivity = activity;
    }
}
